const MYCP_CLIENT_ID = 'MYCP-CLIENT-ID-NEW';
const newUUID = (nonce) => {
  let d = new Date().getTime();
  let tpl = nonce ? 'xxxxxxxxxxxxxyxxxxyxxxxxxxxxxxxx' : 'xxxxxxx-xxxx-5xxx-yxxx-xxxxxxxxx';
  let uuid = tpl.replace(/[xy]/g,
    function (c) {
      let r = (d + Math.random() * 16) % 16 | 0;
      d = Math.floor(d / 16);
      return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
    });
  return uuid;
};

const getClientID = () => {
  let _clientID = localStorage.getItem(MYCP_CLIENT_ID)
  if (!_clientID) {
    _clientID = newUUID();
    localStorage.setItem(MYCP_CLIENT_ID, _clientID)
  }
  return _clientID;
};

const randomInt = (min, max) => {
  return Math.floor(Math.random() * (max - min + 1) + min);
};

const getCurrentPage = () => {
  return location.href
}

export default {
  newUUID,
  getClientID,
  randomInt,
  getCurrentPage: getCurrentPage
}
